<?php

declare(strict_types=1);

namespace App\Cola\Model;

use Hyperf\Database\Model\Events\Created;
use Hyperf\Database\Model\SoftDeletes;
use Mine\MineModel;

/**
 * @property int $id 
 * @property string $title 标题
 * @property int $user_id 用户id
 * @property string $img 封面
 * @property int $is_default 是否默认:0=否,1=是
 * @property \Carbon\Carbon $created_at 
 * @property \Carbon\Carbon $updated_at 
 * @property string $deleted_at 
 */
class ColaLedger extends MineModel
{
    use SoftDeletes;
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'cola_ledger';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'title', 'user_id', 'img', 'is_default', 'created_at', 'updated_at', 'deleted_at'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'is_default' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function created(Created $event)
    {
        // 保存更新
        $this->weigh = $this->id;
        $this->save();
    }

    /**
     * 多对多关联账单
     * */
    public function bills()
    {
        return $this->belongsToMany(ColaBill::class);
    }

}
